package com.example.xpvideo.Controller;

import com.example.xpvideo.entity.PageResult;
import com.example.xpvideo.entity.PurchaseCoupon;
import com.example.xpvideo.entity.ResponseResult;
import com.example.xpvideo.entity.req.CommodityListReq;
import com.example.xpvideo.entity.req.FullCouponReq;
import com.example.xpvideo.entity.req.PInstantCouponReq;
import com.example.xpvideo.entity.req.PublicReq;
import com.example.xpvideo.entity.res.CommodityListRes;
import com.example.xpvideo.service.PurchaseCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 优惠券管理
 *
 * @author : 洪俊新
 * @date : 2021/7/22 14:23
 * @description:
 */
@RestController
@RequestMapping("/back/coupon")
public class CouponController {
    @Autowired
    private PurchaseCouponService purchaseCouponService;

    /**
     * 优惠券列表
     * */
    @GetMapping("/list")
    public ResponseResult<PageResult<List<PurchaseCoupon>>> list(PublicReq publicReq)
            throws Exception{
        return purchaseCouponService.list(publicReq);
    }

    /**
     * 上架满减优惠券
     */
    @PostMapping("/insertpfullcoupon")
    public ResponseResult<Object> insertPFullCoupon(
            @RequestBody @NotNull
            FullCouponReq fullCouponReq)
            throws Exception {
        return purchaseCouponService.pfullCounponInsert(fullCouponReq);
    }


    /**
     * 上架立减优惠券
     */
    @PostMapping("/pinstantcoupon")
    public ResponseResult<Object> pinstantFullCoupon(
            @RequestBody @NotNull
                    PInstantCouponReq pInstantCouponReq)
            throws Exception {
        return purchaseCouponService.pInstantCounponInsert(pInstantCouponReq);
    }

}
